<template>
  <div> 
      <div class="ms-title">添加新设备</div>
        <div class="ms-new-device">
            <el-form :model="ruleForm" ref="ruleForm" label-width="0px">
                <el-form-item prop="name">
                    <el-input v-model="ruleForm.name" placeholder="设备名称"></el-input>
                </el-form-item>
                <div>
                    <el-button type="primary" @click="submitForm()">添加</el-button>
                </div>
            </el-form>
    </div>
  </div>
</template>

<script>
export default {
    data() {
        return {
            ruleForm:{
                name:""
            }
        }
    },
    methods: {
        submitForm() {
            this.loading = true;
            this.$axios.post('/api/device', this.ruleForm).then((res) => {
                if (res.data.code == 0) {
                    this.$message({
                        message: '创建设备成功',
                        type: 'success'
                    });
                    this.ruleForm.name = '';
                }
                else {
                     this.$message.error({
                        message: '创建设备失败'
                    });
                    this.ruleForm.name = '';
                }
            });
            this.loading = false;
        }
    }
}
</script>

<style scoped>
.ms-new-device{
    position: absolute;
    left: 50%;
    top: 50%;
    width: 300px;
    height: 160px;
    margin: -150px 0 0 -190px;
    padding: 40px;
    border-radius: 5px;
    background: #fff;
}
</style>